package com.jiangwz.sort;

/**
 * @author jiangwz
 * @create 2021/3/17.
 */
public class UnNamedSort extends BaseSort {

    public static void main(String[] args) {
        int[] arr = new int[]{9, 1, 3, 2, 5, 6, 8, 7, 4};
//        int[] arr = new int[]{9, 1, 3, 2, 5, 6, 8, 7, 4,11};
        sort(arr);
    }

    /**
     * 交换过程
     * [9, 1, 3, 2, 5, 6, 8, 7, 4]
     * [9, 1, 3, 2, 5, 6, 8, 4, 7]
     * [9, 1, 3, 2, 5, 6, 4, 8, 7]
     * [9, 1, 3, 2, 5, 4, 6, 8, 7]
     * [9, 1, 3, 2, 4, 5, 6, 8, 7]
     * [9, 1, 2, 3, 4, 5, 6, 8, 7]
     * [1, 9, 2, 3, 4, 5, 6, 8, 7]
     * [1, 9, 2, 3, 4, 5, 6, 7, 8]
     * [1, 2, 9, 3, 4, 5, 6, 7, 8]
     * [1, 2, 3, 9, 4, 5, 6, 7, 8]
     * [1, 2, 3, 4, 9, 5, 6, 7, 8]
     * [1, 2, 3, 4, 5, 9, 6, 7, 8]
     * [1, 2, 3, 4, 5, 6, 9, 7, 8]
     * [1, 2, 3, 4, 5, 6, 7, 9, 8]
     * [1, 2, 3, 4, 5, 6, 7, 8, 9]
     * [1, 2, 3, 4, 5, 6, 7, 8, 9]
     *
     * @param arr
     */
    public static void sort(int[] arr) {
        print(arr);
        // 第一次循环交换把最小值移到第一位
        // 第二次循环交换把最小值移到第二位
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = (arr.length - 1); j > i; j--) {
                if (arr[j] < arr[j - 1]) {
                    swap(arr, j, j - 1);
                }
                print(arr);
            }
        }


    }
}
